<?php
/**
 * Created by PhpStorm.
 * Author: Shadow
 * Date: 2022/1/11
 * Time: 7:25 下午
 * description: Brand.php
 * 品牌业务逻辑类
 */

namespace app\adminapi\business;


use think\Exception;

class Brand {
    /**
     * 获取详情
     * @param $id
     * @return array
     * @throws \think\Exception
     */
    public static function getInfo($id){
        return \app\common\model\Brand::with('category')->field('id,name,logo,desc,url,sort,cate_id')->find($id)->toArray();
    }

    /**
     * 删除品牌
     * @param $id
     * @return bool
     * @throws Exception
     */
    public static function delete($id){
        $isGods = \app\common\model\Goods::where('brand_id',$id)->find();
        if ($isGods) {
            throw  new Exception("该品牌下有商品、不能删除");
        }
        $result = \app\common\model\Brand::destroy($id);
        if (!$result) {
            throw  new Exception("删除失败");
        }
        return true;
    }
}